//
//  NRWCarRootViewController.m
//  New_Runway
//
//  Created by mack on 2018/1/22.
//  Copyright © 2018年 NelsonJ. All rights reserved.
//

#import "NRWCarRootViewController.h"

@interface NRWCarRootViewController ()<UIGestureRecognizerDelegate>
@end

@implementation NRWCarRootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.tabH = height_tabbar;
    self.navH = height_navbar;
    self.BotH = bottom_height;
    [self networkStatusNotReachable];
    
    if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]){
        self.navigationController.interactivePopGestureRecognizer.delegate =self;
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
        
    }
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];//白色
}
-(void)setValue:(id)value forUndefinedKey:(NSString *)key{
    
}
- (void)viewDidAppear:(BOOL)animated{
    
    [super viewDidAppear:animated];
#ifdef DEBUG
    NSLog(@"viewDidAppear %@", self.class);
#else
    [MobClick beginLogPageView:self.navigationBarView.titleLabel.text];
#endif
}

- (void)viewDidDisappear:(BOOL)animated {
    
    [super viewDidDisappear:animated];
    
#ifdef DEBUG
#else
    [MobClick endLogPageView:self.navigationBarView.titleLabel.text];
#endif
}

- (void)dealloc {
    
#ifdef DEBUG
    NSLog(@"dealloc %@", self.class);
#endif
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)networkStatusNotReachable{
    __weak typeof(self.view)weakSelf = self.view;
    
    _navigationBarView = [[NRWCarNavigationView alloc] initWithController:self andTitle:nil andStyle:navgationStyle_deepColor];
    [self.view addSubview:_navigationBarView];
    [_navigationBarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf).with.offset(0);
        make.left.equalTo(weakSelf).with.offset(0);
        make.height.mas_equalTo(self.navH);
        make.right.equalTo(weakSelf).with.offset(0);
    }];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
    
    
}

- (void)mainTabBarFirstSelect
{
    
    
}
- (void)mainTabBarSelectAgain{
    
    
}
-(void)rightItemClick{
  

}

- (void)callPhoneWithPhoneNum:(NSString *)phoneNum {
    
    NSString *str1 = [phoneNum substringToIndex:3];
    NSString *str2 = [phoneNum substringWithRange:NSMakeRange(3, 4)];
    NSString *str3 = [phoneNum substringWithRange:NSMakeRange(7, 4)];
    NSString *tel = [NSString stringWithFormat:@"%@-%@-%@", str1, str2, str3];
                          
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:tel preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
    }];

    UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"呼叫" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        
        NSString *str = [NSString stringWithFormat:@"tel:%@", phoneNum];
        if (@available(iOS 10.0, *)) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str] options:@{} completionHandler:^(BOOL success) {
                
            }];
        } else {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
        }
    }];
    
    [alertController addAction:cancelAction];
    [alertController addAction:otherAction];
    [self presentViewController:alertController animated:YES completion:nil];
}

@end
